﻿using System;
using System.Data.Common;
using System.Data;
using YiYiTong.Rocket.Entity;
using YiYiTong.Rocket.Helper;

namespace YiYiTong.Rocket.DataAccess
{
    public class MerchantDataAccess
    {
        #region 单例模式
        private MerchantDataAccess()
        {
        }

        private static MerchantDataAccess _instance;
        private static readonly object _syncObject = new object();

        public static MerchantDataAccess Instance
        {
            get
            {
                if (_instance == null)
                {
                    lock (_syncObject)
                    {
                        if (_instance == null)
                        {
                            _instance = new MerchantDataAccess();
                        }
                    }
                }
                return _instance;
            }
        }
        #endregion 单例模式

        /// <summary>
        /// 根据id获取商户信息
        /// </summary>
        /// <param name="merId"></param>
        /// <returns></returns>
        public MerchantInfo GetMerchant(int merId)
        {
            MerchantInfo info = new MerchantInfo();
            try
            {
                DBHelper db = DBFactory.AdminDB;
                string strSql = "select * from MerchantInfo where MerId=@merId";
                DbCommand Procdbcomm = db.GetSqlStringCommand(strSql);
                db.AddInParameter(Procdbcomm, "@merId", DbType.Int32, merId);
                var ds = db.ExecuteDataSet(Procdbcomm);
                if (ds != null && ds.Tables[0] != null && ds.Tables[0].Rows.Count != 0)
                    info = new ModelHandler<MerchantInfo>().FillModel(ds.Tables[0].Rows[0], false, false);
            }
            catch (Exception ex)
            {
                //记录日志
                LogHelper.Error("根据id获取商户信息-GetMerchant" + ex.ToString());
            }
            return info;
        }
    }
}
